//
//  ZBBProvinceControllViewCell.m
//  沙哈拉FM
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 S1mpl3. All rights reserved.
//

#import "ZBBProvinceControllViewCell.h"
#import "TwoToOne.h"
#import "FitHeader.h"
#import "ZBBPlayHistory.h"
#import "ZBBRadioViewController.h"
@implementation ZBBProvinceControllViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _collectionView  = [[ UICollectionView alloc]initWithFrame:CGRectMake(0, -50 * FITWidth, self.frame.size.width, 617 * FITHeight - 64 * FITHeight) collectionViewLayout:flowLayout];
        
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        
        [self addSubview:_collectionView];
        [_collectionView registerClass:[ZBBLocationViewControllViewCell class] forCellWithReuseIdentifier:@"locationCell"];
        
    }
    return self;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataSourceArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ZBBLocationViewControllViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"locationCell" forIndexPath:indexPath];
    
    cell.zmodel = _dataSourceArray[indexPath.row];
    
    
    return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.frame.size.width, 90);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic =  _array[indexPath.row];
    
    
   
    [ZBBRadioViewController shareInstance].dic = _array[indexPath.row];
    [self.nav pushViewController:[ZBBRadioViewController shareInstance]animated:YES];
     [[ZBBPlayHistory shareInstance] takeHistoryArrayFromFile:@"ppppp"];
    [[ZBBPlayHistory shareInstance] addDictionary:dic];
    [[ZBBPlayHistory shareInstance] WriteToFile:@"ppppp"];
    
    
    
    
    
    
    
}
-(void)setUrlString:(NSString *)urlString
{
    NSString *url= [NSString stringWithFormat:@"http://live.ximalaya.com/live-web/v1/getRadiosListByType?pageNum=1&radioType=2&device=android&provinceCode=%@&pageSize=15", urlString];
    _dataSourceArray = [NSMutableArray array];
    [TwoToOne getDataByString:url
                   BodyString:nil WithDataBlock:^(id data) {
                       _array = [data objectForKey:@"result"];
                       NSArray *array = [data objectForKey:@"result"];
                       for (NSDictionary *dic in array) {
                           ZBBLocationModel *model = [[ZBBLocationModel alloc]init];
                           [model setValuesForKeysWithDictionary:dic];
                           [_dataSourceArray addObject:model];
                           
                       }
                       [_collectionView reloadData];
                       
                       
                       
                   }];
    
    
}

@end

